<?php
namespace app\admin\controller;
use think\Db;
use app\common\controller\Base;
class Login extends Base{
    public function login(){
        if(request()->isPost()){
            $data=input('post.');            	
            if(empty($data['username'])){
                $this->error('用户名不能为空！');
            }elseif(empty($data['password'])){
                $this->error('密码不能为空！');
            }
            $user_info=Db::name('user')->where('username',$data['username'])->find();
            //dump($user_info);
            if($user_info&&$user_info['status']==1){
                if(md5($data['password'])==$user_info['password']){
                    $group=Db::name('auth_group_access')->where('uid',$user_info['id'])->find();
                    	
                    $auth = array(
                        'uid'             => $user_info['id'],
                        'username'        => $user_info['username'],
                        'group_id'			  => $group['group_id']
                    );
                    	
                    session('user_auth', $auth);
                    return ['msg'=>"登录成功！",'status'=>true];
                   
                }else{
                    return $this->error("密码错误！");
                }
            }else{
                $this->error("用户不存在或被禁用！");
            }
        }
        return $this->fetch('public/login');
    }
    public function logout(){
        session('user_auth',null);
        $this->redirect('Login/login');
    }
}